import QtQuick 2.2
import QtQuick.Controls 2.0

Item {
  id: itemTreeDelegate
  height: 80
  width: itemTreeDelegate.ListView.view.width

/*****************************************************************************
  选择Delegate
******************************************************************************/
  function bestDelegate(t) {
    if(t === 0)
      return actionDelegate;
    return txtDelegate; // t == "text"
  }
/*****************************************************************************
    action组件
******************************************************************************/
  Component {
    id: actionDelegate

        Item {
            id: item1
            width: 511
            height: 72

            Text {
                id: text1
                width: 369
                text: value //填入数据
                anchors.left: parent.left
                anchors.leftMargin: 26
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 24
                anchors.top: parent.top
                anchors.topMargin: 12
                font.family: "Tahoma"
                font.pixelSize: 29
            }

            Rectangle {
                id: rectFlag
                x: 450
                width: 44
                color: "#00000000"
                radius: 22
                anchors.top: parent.top
                anchors.topMargin: 11
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 15
                anchors.right: parent.right
                anchors.rightMargin: 17
                border.color: "#b30707"
                border.width: 6

                MouseArea {
                    id: mouseArea2
                    anchors.fill: parent
                }
            }

            Text {
                id: projectTxt
                x: 41
                y: 49
                width: 48
                height: 17
                text: "· 无项目"
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: 12

                MouseArea {
                    id: mouseArea1
                    anchors.fill: parent
                }
            }

            Text {
                id: contentTxt
                x: 95
                y: 49
                width: 78
                height: 17
                text: qsTr("·无上下文")
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: 12

                MouseArea {
                    id: mouseArea3
                    anchors.fill: parent
                }
            }

            Text {
                id: text2
                x: 288
                y: 52
                width: 89
                height: 14
                text: qsTr("Text")
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: 12
            }

            Rectangle {
                id: rectangle2
                width: 7
                color: "#89dafb"
                anchors.left: parent.left
                anchors.leftMargin: 0
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 0
                anchors.top: parent.top
                anchors.topMargin: 0
            }

        }

        Connections {
            target: mouseArea3
            onDoubleClicked: print("clicked")
        }
  }
/*****************************************************************************
    基本“文本”组件
******************************************************************************/
  Component {
    id: txtDelegate

    Text {
      id: txt
      text: value
      verticalAlignment: Text.AlignVCenter
      horizontalAlignment: Text.AlignHCenter
    }
  }
/*****************************************************************************
  动态加载
******************************************************************************/
  Loader {
    id: itemDisplay
    anchors.fill: parent;
    anchors.topMargin: 2
    anchors.bottomMargin: 2
    sourceComponent: bestDelegate(children.count)
  }
}
